package com.me.jingdongshop.ui.activity;

import android.content.Intent;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.me.common.base.BaseActivity;
import com.me.common.base.Global;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.HomeQuick;
import com.me.jingdongshop.model.protocol.IHttpService;
import com.me.jingdongshop.presenter.TestFragmentPre;
import com.me.jingdongshop.ui.adapter.HomePromotionLetterAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuer on 2017/5/6/006.
 * 促销快报
 */
public class HomePromotionLettersActivity extends BaseActivity {
    private ImageView ivHeadBack;
    private ImageView ivHeadCart;

    private RecyclerView recyclerView;
    private HomePromotionLetterAdapter homePromotionLetterAdapter;
    private HomeQuick homeQuick;
    private List<HomeQuick.TopicBean> myTopicBeen;
    @Override
    public int getLayoutRes() {
        return R.layout.activity_home_promotion_letter;
    }

    @Override
    public void initView() {
        ivHeadBack = (ImageView) findViewById(R.id.iv_head_back);
        ivHeadBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ivHeadCart = (ImageView) findViewById(R.id.iv_head_cart);
    }

    @Override
    public void initListener() {

    }
    TestFragmentPre mTestFragmentPre;
    @Override
    public void initData() {
        mTestFragmentPre = new TestFragmentPre(this);
        mTestFragmentPre.getHomeQuick();
    }

    @Override
    public void onClick(View v, int id) {
        recyclerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Global.mContext, GoodsDetailActivity.class);//跳转到商品详情
                Global.mContext.startActivity(intent);
                return;
            }
        });
    }

    @Override
    public void onHttpSuccess(int reqType, Message msg) {
       if (reqType== IHttpService.HTTP_TOPIC){
           homeQuick= (HomeQuick) msg.obj;
           myTopicBeen=homeQuick.getTopic();
           List<List<HomeQuick.TopicBean>> list=new ArrayList<>();
           list.add(myTopicBeen);
           initRecyclerView();
       }
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.home_rv_promotion_letter);

        recyclerView.setLayoutManager(new GridLayoutManager(this,2));
        homePromotionLetterAdapter = new HomePromotionLetterAdapter(myTopicBeen);
        recyclerView.setAdapter(homePromotionLetterAdapter);
        homePromotionLetterAdapter.notifyDataSetChanged();
    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
